<template>
  <div class="user-avator-dropdown">
    <Dropdown @on-click="handleClick">
      <Badge >  <!-- :dot="!!messageUnreadCount"  -->
       <!-- <Avatar :src="userAvator"/>-->
        <span> {{ this.$store.state.user.userName}} </span>
      </Badge>
      <Icon :size="18" type="md-arrow-dropdown"></Icon>
      <DropdownMenu slot="list">
        <!-- <DropdownItem name="log">
          我的日志
        </DropdownItem> -->
        <DropdownItem name="logout">退出登录</DropdownItem>
        
        <!-- <DropdownItem name="message">
          消息中心<Badge style="margin-left: 10px" :count="messageUnreadCount"></Badge>
        </DropdownItem> -->
       
      </DropdownMenu>
    </Dropdown>
  </div>
</template>

<script>
import './user.less'
import { mapActions } from 'vuex'
export default {
  name: 'User',
  props: {
    userAvator: {
      type: String,
      default: ''
    },
    messageUnreadCount: {
      type: Number,
      default: 0
    }
  },
  methods: {
    ...mapActions([
      'handleLogOut'
    ]),
    logout () {
      var $this = this;
      this.$Modal.confirm({
        title:"退出确认",
        content:"确定要退出系统吗?",
        okText:"确定退出",
        cancelText:"再想想",
        loading:true,
        onOk(){

          setTimeout(function(){
            $this.handleLogOut().then(() => {
            $this.$Modal.remove();
            $this.$router.push({
              name: 'login'
            })
          })
          },1500);
        }
      });
    },
    log () {
      const route = {
        name: "log_page",
        meta: {
          title: "我的日志"
        }
      };
      this.$router.push(route);
    },
    message () {
      this.$router.push({
        name: 'message_page'
      })
    },
    handleClick (name) {
      switch (name) {
        case 'logout': this.logout()
          break
        case 'log': this.log()
          break
        case 'message': this.message()
          break
      }
    }
  }
}
</script>
